/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.ez2find.controllers;

import com.ez2find.manager.RegisterUserManagerLocal;
import com.ez2find.model.RegisterUser;
import com.ez2find.util.SessionContext;
import java.io.*;
import java.net.*;
import javax.ejb.EJB;
import javax.servlet.*;
import javax.servlet.http.*;

/**
 *
 * @author Owner
 */
public class Confirmation extends HttpServlet {
   
    /** 
    * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
    * @param request servlet request
    * @param response servlet response
    */
    
    @EJB
    private RegisterUserManagerLocal ejbUserManager;
    
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        RegisterUser registerUser = ejbUserManager.findUserForConfirmation(request.getParameter("id"), request.getParameter("cc"));
        if(registerUser!=null){
            SessionContext.setAttribute("user", registerUser);
            getServletContext().getRequestDispatcher("/user/confirmation.jsp").forward(request, response);
        }
        else{
            response.setContentType("text/html"); 
            PrintWriter out = response.getWriter(); 
            out.println("<html>");
            out.println("<head><title>ez2find</title></head>");
            out.println("<body>");
            out.println("<h2>Error</h2>");
            out.println("<h4>Your account expired or this invalid direction</h4>");
            out.println("<a href=\"/site-es/faces/welcome.jsp\" >Go to eez2find.com</a>");
            out.println("</body></html>");
        }
        
    } 

    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /** 
    * Handles the HTTP <code>GET</code> method.
    * @param request servlet request
    * @param response servlet response
    */
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        processRequest(request, response);
    } 

    /** 
    * Handles the HTTP <code>POST</code> method.
    * @param request servlet request
    * @param response servlet response
    */
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        processRequest(request, response);
    }

    /** 
    * Returns a short description of the servlet.
    */
    public String getServletInfo() {
        return "Short description";
    }
    // </editor-fold>
}
